var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var helpers = require('./helpers');
const AssetsPlugin = require('assets-webpack-plugin');
//const NormalModuleReplacementPlugin = require('webpack/lib/NormalModuleReplacementPlugin');
//const ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin');
const CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
//const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin;
const ForkCheckerPlugin = require('awesome-typescript-loader').ForkCheckerPlugin;
//const HtmlElementsPlugin = require('./html-elements-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
//const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin');
//const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin');
//const ngcWebpack = require('ngc-webpack');
module.exports = {
  entry: {
    'polyfills': './src/polyfills.ts',
    'vendor': './src/vendor.ts',
    'app': './src/main.ts'
  },

  resolve: {
    extensions: ['', '.ts', '.js','html','css']
  },

  module: {
    loaders: [
      /**
       * 设置ts文件
       */
      {
        test: /\.ts$/,
        loaders: ['awesome-typescript-loader', 'angular2-template-loader','angular2-load-children-loader']
      },
      /**
       * 设置html文件
       */
      {
        test: /\.html$/,
        loader: 'html'
      },
      /**
       * 设置图片资源
       */
      {
        test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
        loader: 'file?name=assets/imgs/[name].[hash].[ext]'
      },
      /**
       * 排除src/app目录下的css，使用style标签直接映射到index.html中
       */
      {
        test: /\.css$/,
        exclude: helpers.root('src', 'app'),
        loader: ExtractTextPlugin.extract('style', 'css?sourceMap')
      },
      /**
       * app内部的css资源
       */
      {
        test: /\.css$/,
        include: helpers.root('src', 'app'),
        loader: 'raw'
      }
    ]
  },

  plugins: [
    new AssetsPlugin({
        path: helpers.root('dist'),
        filename: 'webpack-assets.json',
        prettyPrint: true
      }),
      
    new webpack.optimize.CommonsChunkPlugin({
      name: ['app', 'vendor', 'polyfills']
    }),
    new ForkCheckerPlugin(),
    new HtmlWebpackPlugin({
      template: 'src/index.html'
    }),
   new ExtractTextPlugin('[hash].css', {allChunks: true, disable: false}),
    new CopyWebpackPlugin([{
				from: 'src/assets',
				to: 'assets'
			}]),
  ]
};